/*
 * GLOBAL.qml 用来定义某些全局变量
 */
import QtQuick 2.14
import Global 1.0

QtObject {
    /** 枚举 */
    // 标签位置枚举
    enum LabelPosition {
        Left = 0x0,
        Top = 0x0001
    }
    // 规则枚举
    enum Rules {
        Required = 0x0001 // 必填
    }

    // 标准按钮枚举
    enum StandardButton{
        NoButton = 0x0,
        Submit = 0x0001, // 确定
        Cancel = 0x0002, // 取消
        Return = 0x0004 // 返回
    }
    // 窗口类型枚举
    enum BoxType {
        Tips = 0x0 // 提示窗口
    }

    // 可选中按钮
    enum CheckableButtonState {
        Default = 0x0, // 默认状态
        Checked = 0x0001 // 选中状态
    }
    // 文字状态
    enum CheckableFontState {
        Default = 0x0002, // 默认状态
        Checked = 0x0004 // 选中状态
    }

    /** 函数 */
    // 创建左边框
    function createLeftBorder(parent, width = 2, color = "#FFCCCCCC", visible = true){
        // 创建canvas绘制边框
        var createLeftBorderStr = `
        import QtQuick 2.14;
        import QtQuick.Controls 2.14;
        Canvas {
        id: canvasLeftBorder

        property string color: "${color}"

        anchors.fill: parent;
        visible: ${visible};
        onPaint: {
        var ctx = getContext("2d")
        ctx.clearRect(0, 0, width, height)
        ctx.strokeStyle = canvasLeftBorder.color;
        ctx.lineWidth = ${width};
        ctx.beginPath();
        ctx.moveTo(0, 0);
        ctx.lineTo(0, height);
        ctx.stroke();
        }
        }
        `
        var leftBorderObj =
                Qt.createQmlObject(createLeftBorderStr, parent)
        return leftBorderObj
    }

    // 创建上边框
    function createTopBorder(parent, width = 2, color = "#FFCCCCCC", visible = true){
        // 创建canvas绘制边框
        var topBorderObj =
                Qt.createQmlObject(`
                                   import QtQuick 2.14;
                                   import QtQuick.Controls 2.14;
                                   Canvas {
                                   id: canvasTopBorder

                                   property string color: "${color}"

                                   anchors.fill: parent;
                                   visible: ${visible};
                                   onPaint: {
                                   var ctx = getContext("2d");
                                   ctx.clearRect(0, 0, width, height)
                                   ctx.strokeStyle = canvasTopBorder.color;
                                   ctx.lineWidth = ${width};
                                   ctx.beginPath();
                                   // 上边框
                                   ctx.moveTo(0, 0);
                                   ctx.lineTo(width, 0);
                                   ctx.stroke();
                                   }
                                   }
                                   `, parent)
        return topBorderObj
    }

    // 创建右边框
    function createRightBorder(parent, width = 2, color = "#FFCCCCCC", visible = true){
        // 创建canvas绘制边框
        var rightBorderObj =
                Qt.createQmlObject(`
                                   import QtQuick 2.14;
                                   import QtQuick.Controls 2.14;
                                   Canvas {
                                   id: canvasRightBorder

                                   property string color: "${color}"

                                   anchors.fill: parent;
                                   visible: ${visible};
                                   onPaint: {
                                   var ctx = getContext("2d");
                                   ctx.clearRect(0, 0, width, height)
                                   ctx.strokeStyle = canvasRightBorder.color;
                                   ctx.lineWidth = ${width};
                                   ctx.beginPath();
                                   // 右边框
                                   ctx.moveTo(width, 0);
                                   ctx.lineTo(width, height);
                                   ctx.stroke()
                                   }
                                   }
                                   `, parent)
        return rightBorderObj
    }

    // 创建下边框
    function createBottomBorder(parent, width = 2, color = "#FFCCCCCC", visible = true){
        // 创建canvas绘制边框
        var bottomBorderObj =
                Qt.createQmlObject(`
                                   import QtQuick 2.14;
                                   import QtQuick.Controls 2.14;
                                   Canvas {
                                   id: canvasBottomBorder

                                   property string color: "${color}"

                                   anchors.fill: parent;
                                   visible: ${visible};
                                   onPaint: {
                                   var ctx = getContext("2d");
                                   ctx.clearRect(0, 0, width, height)
                                   ctx.strokeStyle = canvasBottomBorder.color;
                                   ctx.lineWidth = ${width};
                                   ctx.beginPath();
                                   // 下边框
                                   ctx.moveTo(0, height);
                                   ctx.lineTo(width, height);
                                   ctx.stroke();
                                   }
                                   }
                                   `, parent)
        return bottomBorderObj
    }
}
